package cn.edu.bjut.homework.chapter5;

public class CharCounter {
    int[] letterCount = new int[26];
    int[] digitCount = new int[10];

    public CharCounter(String str) {
        str = str.toLowerCase();
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (Character.isLetter(ch)) {
                letterCount[ch - 'a']++;
            } else if (Character.isDigit(ch)) {
                digitCount[ch - '0']++;
            }
        }
    }

    public int[] getLetterCount() {
        return letterCount;
    }

    public int[] getDigitCount() {
        return digitCount;
    }

    public int getCharCount(char ch) {
        if (Character.isLetter(ch)) {
            return letterCount[ch - 'a'];
        } else if (Character.isDigit(ch)) {
            return digitCount[ch - '0'];
        } else {
            return 0;
        }
    }
}
